package com.sdry.web.controller.hpf;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.hpf.Page;
import com.sdry.model.hpf.PickApplyDetail;
import com.sdry.service.hpf.PickApplyDetailService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * @ClassName: pickApplyDetailController 
 * @Description:领料申请单详情Controller
 * @Author hpf
 * @Date 2018年10月9日 下午3:12:57 
 * @version 1.0
 */
@RequestMapping(value="/pickApply")
@Controller
public class PickApplyDetailController {

	@Resource
	private PickApplyDetailService pickApplyDetailService;
	
	/**
	 * 分页查询领料申请单详情
	 * @param page 分页条件
	 * @param pickApplyDetail 查询条件
	 * @param response
	 */
	@RequestMapping(value="/listPagePickApplyDetail")
	public void listPagePickApplyDetail(Page page,PickApplyDetail pickApplyDetail,HttpServletResponse response){
		Map<String, Object> map = new HashMap<>();
		map.put("page", page.getPage());
		map.put("limit", page.getLimit());
		map.put("pickID", pickApplyDetail.getPickID());
		
		List<PickApplyDetail> pickApplyDetailList = pickApplyDetailService.listPagePickApplyDetail(map);
		int count = pickApplyDetailService.countPickApplyDetail(pickApplyDetail);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(pickApplyDetailList, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", count);
		try {
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 条件查询所有领料申请单详情
	 * @param pickApplyDetail 查询条件
	 * @param response
	 */
	@RequestMapping(value="/listAllPickApplyDetail")
	public void listAllLineSideStockInDetail(PickApplyDetail pickApplyDetail,HttpServletResponse response){
		List<PickApplyDetail> pickApplyDetailList = pickApplyDetailService.listAllPickApplyDetail(pickApplyDetail);
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(pickApplyDetailList, jsonConfig);
		try {
			ResponseUtil.write(response, jsonArray);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 条件查询所有领料申请单详情
	 * @param pickApplyDetail 查询条件
	 * @param response
	 */
	@RequestMapping(value="/listAllAndroidPickApplyDetail")
	public void listAllAndroidPickApplyDetail(String pickID,HttpServletResponse response){
		PickApplyDetail pickApplyDetail = new PickApplyDetail();
		pickApplyDetail.setPickID(Long.parseLong(pickID));
		List<PickApplyDetail> pickApplyDetailList = pickApplyDetailService.listAllPickApplyDetail(pickApplyDetail);
		JSONObject jsonObject = new JSONObject();
		JSONArray jsonArray = JSONArray.fromObject(pickApplyDetailList);
		try {
			if(pickApplyDetailList.size()>0){
				jsonObject.put("state", 1);
				jsonObject.put("message", "查找成功");
				jsonObject.put("data", jsonArray);
			}else{
				jsonObject.put("state", 0);
				jsonObject.put("message", "查找失败");
				jsonObject.put("data", null);
			}
			ResponseUtil.write(response, jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
